package com.sinoglobal.dumping.activity;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.TextView;

import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.base.Dumpling_ShareAbstractActivity;
import com.sinoglobal.dumping.base.Dumpling_SinoConfig;
import com.sinoglobal.dumping.base.Dumpling_SinoConstans;
import com.sinoglobal.wallet.activity.W_HomeActivity;
import com.umeng.socialize.bean.SHARE_MEDIA;

public class Dumpling_MyCashStatusActivity extends Dumpling_ShareAbstractActivity {

    private int status;
    private TextView userPhone;
    private TextView stateDescription;
    private String shareUrl;
    private String shareContent;
    private String shareTitle;
    private String sharePicUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dumpling__activity_my_cash_status);
        initData();
        initView();
    }

    private void initData() {
        status = 2;//状态设置
        if (status == 1) {
            shareUrl = Dumpling_SinoConfig.sMakeShare.getResultList().getUrl() + "/?name=" + Dumpling_SinoConstans.USER_NAME + "&productCode=" + Dumpling_SinoConstans.PRODUCT_CODE + "&pannikin_id=" + getIntent().getStringExtra("paySuccessId");
            shareContent=Dumpling_SinoConfig.sMakeShare.getResultList().getContent();
            shareTitle=Dumpling_SinoConfig.sMakeShare.getResultList().getTitle();
            sharePicUrl=Dumpling_SinoConfig.sMakeShare.getResultList().getPicurl();
        }
    }

    private void initView() {
        userPhone = (TextView) findViewById(R.id.cash_user_phone);
        stateDescription = (TextView) findViewById(R.id.cash_state_description);
        //设置电话号码
        userPhone.setText(Dumpling_SinoConstans.USER_NAME);
        switch (status) {
            case 1://未领完
                stateDescription.setText(getResources().getText(R.string.dumpling_cash_state_description_go_on));
                ViewStub shareInflate = (ViewStub) findViewById(R.id.cash_status_share_inflate);
                View shareAfterInflate = shareInflate.inflate();
                shareAfterInflate.setVisibility(View.VISIBLE);
                Button shareWX = (Button) shareAfterInflate.findViewById(R.id.cash_share_wx);
                Button shareQQ = (Button) shareAfterInflate.findViewById(R.id.cash_share_qq);
                shareWX.setOnClickListener(this);
                shareQQ.setOnClickListener(this);
                break;
            case 2://吃光了
                stateDescription.setText(getResources().getText(R.string.dumpling_cash_state_description_none));
                ViewStub starInflate = (ViewStub) findViewById(R.id.cash_status_star_inflate);
                View starAfterInflate = starInflate.inflate();
                starAfterInflate.setVisibility(View.VISIBLE);
                Button star = (Button) starAfterInflate.findViewById(R.id.cash_star);
                star.setOnClickListener(this);
                break;
            case 3://领取成功
                stateDescription.setText(getResources().getText(R.string.dumpling_cash_state_description_success));
                ViewStub successInflate = (ViewStub) findViewById(R.id.cash_status_success_inflate);
                View successAfterInflate = successInflate.inflate();
                successAfterInflate.setVisibility(View.VISIBLE);
                TextView stateNumber = (TextView) successAfterInflate.findViewById(R.id.cash_state_number);
                String cash = "0.88元";
                SpannableString styledText = new SpannableString(cash);
                int length = cash.length();
                styledText.setSpan(new TextAppearanceSpan(this, R.style.dumpling_cash_num), 0, length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                styledText.setSpan(new TextAppearanceSpan(this, R.style.dumpling_cash_unit), length - 1, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                stateNumber.setText(styledText, TextView.BufferType.SPANNABLE);
                Button goOn = (Button) successAfterInflate.findViewById(R.id.cash_go_on);
                Button check = (Button) successAfterInflate.findViewById(R.id.cash_check);
                goOn.setOnClickListener(this);
                check.setOnClickListener(this);
                break;
            case 4://已过期
                stateDescription.setText(getResources().getText(R.string.dumpling_cash_state_description_back));
                ViewStub expiredInflate = (ViewStub) findViewById(R.id.cash_status_expired_inflate);
                View expiredAfterInflate = expiredInflate.inflate();
                expiredAfterInflate.setVisibility(View.VISIBLE);
                Button onceMore = (Button) expiredAfterInflate.findViewById(R.id.cash_share_once_more);
                Button myWallet = (Button) expiredAfterInflate.findViewById(R.id.cash_share_my_wallet);
                onceMore.setOnClickListener(this);
                myWallet.setOnClickListener(this);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

    }
    

    @Override
    public void onAntiViolence(View v) {
        if (v.getId() == R.id.cash_share_wx) {//微信分享
            setShare(shareContent,shareTitle,SHARE_MEDIA.WEIXIN,shareUrl,0,sharePicUrl);
        } else if (v.getId() == R.id.cash_share_qq) {//QQ分享
            setShare(shareContent,shareTitle,SHARE_MEDIA.QQ,shareUrl,0,sharePicUrl);
        } else if (v.getId() == R.id.cash_star) {//捞饺子
            goIntent(Dumpling_MainActivity.class);
        } else if (v.getId() == R.id.cash_go_on) {//继续捞
            goIntent(Dumpling_MainActivity.class);
        } else if (v.getId() == R.id.cash_check) {//查看我的饺子
            goIntent(Dumpling_MyDumplingActivity.class);
        }else if (v.getId() == R.id.cash_share_once_more) {//再去包一个
            goIntent(Dumpling_MakeDumplingActivity.class);
        }else if (v.getId() == R.id.cash_share_my_wallet) {//我的钱包
            goIntent(W_HomeActivity.class);
        }
    }
}
